<template>
    <LoadingComponent v-if="isLoading"></LoadingComponent>
</template>

<script type="text/javascript">
    import LoadingComponent from 'components/loading'
    export default {
        components: { LoadingComponent },
        props: ['data'],
        data () {
            return {
                isLoading:false,
            }
        },
        created () {
            this.alertError();
            console.log(this.data)
        },
        methods: {
            alertError () {
                this.$confirm(this.data.title, '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // this.isLoading = true;
                    this.$store.state.loading = true;
                    this.axios.get(this.$store.state.api + 'emp/del', {
                        params: {
                            id:this.data.index
                        }
                    }).then( res => {
                        console.log(res)
                        if (res.data.code == 1) {
                            // this.isLoading = false;
                            this.$store.state.loading = false;
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });

                            if (this.data.type == 'single') {
                                this.$emit('close',{type:'singleDelete',cancel:false})
                            }else{
                                this.$emit('close',{type:'multipleDelete',cancel:false})
                            }
                        }else{
                            this.$store.state.loading = false;
                        }
                        
                    }).catch( res => {
                        console.log(res)
                        // this.isLoading = false;
                        this.$store.state.loading = false;
                        // alert("删除失败")
                        this.$store.dispatch('showAlert',res.data.msg)

                        if (this.data.type == 'single') {
                                this.$emit('close',{type:'singleDelete',cancel:true})
                        }else{
                                this.$emit('close',{type:'multipleDelete',cancel:true})
                        }
                    })
                    // this.$message({
                    //     type: 'success',
                    //     message: '删除成功!'
                    // });
                    
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });

                    if (this.data.type == 'single') {
                        this.$emit('close',{type:'singleDelete',cancel:true})
                    }else{
                        this.$emit('close',{type:'multipleDelete',cancel:true})
                    }
                });
            }
        }
    }
</script>

    